/*
 * Copyright (c) 2019.  drakelee.base All rights reserved.
 */

package com.base.components.database.dao.base;

import com.base.components.common.dto.page.DataPage;
import org.hibernate.transform.ResultTransformer;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.Map;

/**
 * 所有自定义拓展dao实现需继承此类
 *
 * @author <a href="drakelee1221@gmail.com">LiGeng</a>
 * @version 1.0.0, 2017-11-28 11:06
 */
public abstract class AbstractExtendDao<T> {
  @PersistenceContext
  protected EntityManager entityManager;

  public Query setMapResult(Query listQuery){
    return JpaHelper.setMapResult(listQuery);
  }

  public Query setTransformerResult(Query listQuery, ResultTransformer resultTransformer){
    return JpaHelper.setTransformerResult(listQuery, resultTransformer);
  }

  public <E> DataPage<E> pageByQuery(Query countQuery, Query listQuery, Integer pageNum, Integer pageSize){
    return JpaHelper.pageByQuery(countQuery, listQuery, pageNum, pageSize);
  }

  public <E> DataPage<E> pageByQuery(Query countQuery, Query listQuery, Map<String, ?> pageParams){
    return JpaHelper.pageByQuery(countQuery, listQuery, pageParams);
  }

  /** pageSize 无限制 */
  public <E> DataPage<E> pageByQueryNoHelper(Query countQuery, Query listQuery, Map<String, ?> pageParams) {
    return JpaHelper.pageByQueryNoHelper(countQuery, listQuery, pageParams);
  }

  /** pageSize 无限制 */
  public <E> DataPage<E> pageByQueryNoHelper(Query countQuery, Query listQuery, Integer pageNum, Integer pageSize) {
    return JpaHelper.pageByQueryNoHelper(countQuery, listQuery, pageNum, pageSize);
  }

}
